<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<form action="" method="post">
	    <table border="1" cellspacing="0" cellpadding="10px" id="stuTable">
	    	<tr>
				<th></th>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
				<th>家庭住址</th>
			</tr>
	    	<tr>
				<td><input type="checkbox" name="inpuname1" id="inputid1" value="10" /></td>
				<td>张三</td>
				<td class="gender">男</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>李四</td>
				<td class="gender">女</td>
				<td>22</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>王五</td>
				<td class="gender">男</td>
				<td>46</td>
				<td>河南省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>李白</td>
				<td class="gender">女</td>
				<td>19</td>
				<td>广东省</td>
			</tr>
	    </table>
		</form>
		<input type="checkbox" name="" id="checkAllId" value="" onclick="doSelAll();"/>全选
			<input type="checkbox" name="" id="checkAllId1" value="" onclick="doSelAll1();"/>全选男
				<input type="checkbox" name="" id="checkAllId2" value="" onclick="doSelAll2();"/>全选女
	    <button type="button">删除</button>
	</body>
	<script type="text/javascript">
		function doSelAll(){
			var stuTableObj = document.getElementById('stuTable');
			var inputAll = stuTableObj.getElementsByTagName('input');
			console.log(inputAll)
			var checkAllValue = document.getElementById('checkAllId');
			console.log(checkAllValue)
			for (var i = 0; i < inputAll.length; i++) {
				inputAll[i].checked = checkAllValue;
			}
		}
		function doSelAll1(){
			var stu_man = document.getElementsByClassName('gender')
						for (var i=0;i<stu_man.length;i++) {
							if(stu_man[i].innerText == '男'){
								var stuTableObj = document.getElementById('stuTable');
								var inputAll = stuTableObj.getElementsByTagName('input');
								var checkAllValue = document.getElementById('checkAllId1').checked
								inputAll[i].checked = checkAllValue
							}
						}
		}
		function doSelAll2(){
					var stu_man = document.getElementsByClassName('gender')
					for (var i=0;i<stu_man.length;i++) {
						if(stu_man[i].innerText == '女'){
							var stuTableObj = document.getElementById('stuTable');
							var inputAll = stuTableObj.getElementsByTagName('input');
							var checkAllValue = document.getElementById('checkAllId2').checked
							inputAll[i].checked = checkAllValue
						}
					}
				}
	</script>
</html>